<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据编号">
              <a-input placeholder="请输入单据编号" v-model="queryParam.serial"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据日期">
              <j-date
                :show-time="true"
                date-format="YYYY-MM-DD HH:mm:ss"
                placeholder="请选择单据日期"
                v-model="queryParam.documentDate"
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="关联单号">
              <a-input placeholder="请输入关联单号" v-model="queryParam.sourceSerial"></a-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button icon="search" type="primary" @click="searchQuery">查询</a-button>
      <a-button icon="reload" type="primary" @click="searchReset">重置</a-button>
      <!--      <a-button icon='plus' type='primary' @click='handleAdd'>新增</a-button>-->
      <a-button icon="download" type="primary" @click="handleExportXls('领料单')">导出</a-button>
      <!--      <a-upload :action='importExcelUrl' :headers='tokenHeader' :multiple='false' :showUploadList='false' name='file'-->
      <!--                @change='handleImportExcel'>-->
      <!--        <a-button icon='import' type='primary'>导入</a-button>-->
      <!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <j-super-query
        ref="superQueryModal"
        :fieldList="superFieldList"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio' }"
        :customRow="clickThenSelect"
        @change="handleTableChange"
      >
        <template slot="isClosed" slot-scope="text">
          <a-tag v-if="text === 0" color="red">未关闭</a-tag>
          <a-tag v-else color="green">关闭</a-tag>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-if="record.status === 0">编辑</a>

          <a-divider type="vertical" v-if="record.status === 0" />
          <a @click="handleDelete(record.id)" v-if="record.status === 0">删除</a>
          <a-divider type="vertical" v-if="record.status === 0" />
          <a @click="handleUndoCheck(record)" v-if="record.status === 1">反审核</a>
          <a-divider type="vertical" v-if="record.status === 1" />
          <a @click="handleCheck(record)" v-if="record.status === 0">审核</a>
          <a-divider type="vertical" v-if="record.status === 0" />
          <a @click="handleClose(record)" v-if="record.isClosed === 0">关闭</a>
          <a @click="handleUndoClose(record)" v-if="record.isClosed === 1">反关闭</a>
        </span>
      </a-table>
    </div>

    <a-tabs defaultActiveKey="1">
      <a-tab-pane tab="调拨单明细" key="1">
        <HfAllocateDetailList :mainId="selectedMainId" ref="HfAllocateDetailList" />
      </a-tab-pane>
    </a-tabs>

    <hfAllocate-modal ref="modalForm" @ok="modalFormOk"></hfAllocate-modal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import HfAllocateModal from './modules/HfAllocateModal'
import { getAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import HfAllocateDetailList from '@views/warehouse/HfAllocateDetailList.vue'

export default {
  name: 'HfAllocateList',
  mixins: [JeecgListMixin],
  components: {
    HfAllocateDetailList,
    HfAllocateModal
  },
  data() {
    return {
      description: '调拨单管理页面',
      // 表头
      columns: [
        {
          title: '单据编号',
          align: 'center',
          dataIndex: 'serial'
        },
        {
          title: '单据日期',
          align: 'center',
          dataIndex: 'documentDate'
        },
        {
          title: '制单',
          align: 'center',
          dataIndex: 'operator'
        },
        {
          title: '审核员',
          align: 'center',
          dataIndex: 'checker'
        },
        {
          title: '审核日期',
          align: 'center',
          dataIndex: 'checkTime'
        },
        {
          title: '审核状态',
          align: 'center',
          dataIndex: 'status_dictText'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark'
        },
        {
          title: '关联单号',
          align: 'center',
          dataIndex: 'sourceSerial'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/warehouse/hfAllocate/checkList',
        delete: '/warehouse/hfAllocate/delete',
        deleteBatch: '/warehouse/hfAllocate/deleteBatch',
        exportXlsUrl: '/warehouse/hfAllocate/exportXls',
        importExcelUrl: 'warehouse/hfAllocate/importExcel',
        check: '/warehouse/hfAllocate/check',
        undoCheck: '/warehouse/hfAllocate/undoCheck',
        close: '/warehouse/hfAllocate/close',
        undoClose: '/warehouse/hfAllocate/undoClose'
      },
      dictOptions: {},
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 5,
        pageSizeOptions: ['5', '10', '50'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      selectedMainId: '',
      isChecked: false,
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {},
    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.id.split(','), [record])
          }
        }
      }
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
      this.selectedMainId = ''
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedMainId = selectedRowKeys[0]
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
      this.$refs.HfAllocateDetailList.isChecked = true
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'serial', text: '单据编号', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'documentDate', text: '单据日期' })
      fieldList.push({ type: 'string', value: 'operator', text: '制单', dictCode: '' })
      fieldList.push({ type: 'string', value: 'checker', text: '审核员', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'checkTime', text: '审核日期' })
      fieldList.push({ type: 'int', value: 'status', text: '审核状态', dictCode: 'hf_check_status' })
      fieldList.push({ type: 'Text', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sourceSerial', text: '关联单号', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
